//
//  MyVC.m
//  Hand-held_kitchen
//
//  Created by 张张烨 on 16/1/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MyVC.h"
#import "UIImage+UIColor.h"
#import "ZongTouwenjian.pch"
#import "CateAnimationLogin.h"
#import "LMenuController.h"
#import "MyCell.h"
#define kWidth [UIScreen mainScreen].bounds.size.width

#import "GuanyuWomen.h"


static const NSTimeInterval kICSDrawerControllerAnimationDuration = 0.5;
static const CGFloat kICSDrawerControllerOpeningAnimationSpringDamping = 0.7f;
static const CGFloat kICSDrawerControllerOpeningAnimationSpringInitialVelocity = 0.1f;
static const CGFloat kICSDrawerControllerClosingAnimationSpringDamping = .50f;
static const CGFloat kICSDrawerControllerClosingAnimationSpringInitialVelocity = 0.5f;

@interface MyVC ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain) LMenuController *menuVC; //动画
@property (nonatomic,retain) UILabel *label;

@property(nonatomic,assign)BOOL ist;
@property(nonatomic,retain)CateAnimationLogin *login; // 登入
@property (nonatomic,retain)UIButton *dengru; // 登入按钮
@property (nonatomic,retain)UIButton *zhuche;// 注册按钮
@property(nonatomic,retain)UITableView *tableView; // table
@property(nonatomic,retain)UIView *view11;
@end

@implementation MyVC

-(void)dealloc
{
    [_menuVC release];
    [_label release];
    [_login release];
    [_dengru release];
    [_zhuche release];
    [_tableView release];
    [_view11 release];
    [super dealloc];
}
// 初始化
//-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
//    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//    if (self) {
//        [self table];
//        [self view1];
//         [self anniu];
//    }
//    return self;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self table];
    [self view1];
    [self anniu];
   
}

-(void)view1{
    self.view11 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375 * KUAN, 250 * GAO)];
    
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375 * KUAN, 250 * GAO)];
    img.image = [UIImage imageNamed:@"美食"];
    [self.view11 addSubview:img];
    _tableView.tableHeaderView = _view11;
    
}





-(void)table{
    self.tableView = [[UITableView alloc]initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    _tableView.dataSource = self;
    _tableView.delegate =self;
     _tableView.contentInset = UIEdgeInsetsMake(0, 0, 90 *GAO, 0);
    [self.view addSubview:_tableView];
    [_tableView registerClass:[MyCell class] forCellReuseIdentifier:@"cell"];
    [_tableView release];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 69 *GAO;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = @"夜间模式";
            break;
        case 1:
            cell.textLabel.text = @"我的收藏";
            break;
        case 2:
            cell.textLabel.text = @"我的缓存";
            break;
        case 3:
            cell.textLabel.text = @"猜你喜欢";
            break;
        case 4:
            cell.textLabel.text = @"版本更新";
            break;
        case 5:
            cell.textLabel.text = @"关于我们";
            break;
        case 6:
            cell.textLabel.text = @"社区规则";
            break;
        default:
            break;
    }
    
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    GuanyuWomen *guanyu = [[GuanyuWomen alloc]init];
    
    [self.navigationController pushViewController:guanyu animated:YES];
}







-(void)anniu
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:@selector(leftItemClick:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0,0, 40 * KUAN, 40 * GAO);
    [button setImage: [UIImage imageNamed:@"sanheng"] forState:UIControlStateNormal];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    //    self.view = [[UIView alloc]initWithFrame:CGRectMake(0, 50,self.view.bounds.size.width, 400)];
    
    LMenuController *menuVC = [[LMenuController alloc] init];
    menuVC.view.layer.anchorPoint = CGPointMake(0, 0);
    menuVC.view.frame = CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height);
    menuVC.view.transform = CGAffineTransformMakeRotation(-M_PI_2);
    [self addChildViewController:menuVC];
    [self.view addSubview:menuVC.view];
    
    
    
    _menuVC = menuVC;

}


-(void)leftItemClick:(UIButton *)btn
{
    btn.selected = !btn.selected;
    _ist  = !_ist;
    
    if (_ist == YES) {
        self.login=[[CateAnimationLogin alloc]initWithFrame:CGRectMake(0, 50 *GAO,self.view.bounds.size.width, 400 * GAO)];
        /**<  登入 */
            self.dengru = [UIButton buttonWithType:(UIButtonTypeSystem)];
        
            _dengru.frame = CGRectMake(30 *KUAN, 380*GAO, (kWidth - 240) *KUAN, 40 *GAO);
        
            [_dengru setTitle:@"登入" forState:(UIControlStateNormal)];
        [_dengru setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [_dengru.layer setBorderWidth:1.0];
        ;
        
            [_dengru addTarget:self action:@selector(dengru:) forControlEvents:(UIControlEventTouchUpInside)];
            [_login addSubview:_dengru];
        
        /**<  注册按钮 */
            self.zhuche = [UIButton buttonWithType:(UIButtonTypeSystem)];
             _zhuche.frame = CGRectMake((60+ kWidth - 240) *KUAN, 380 * GAO, (kWidth - 240) *KUAN, 40 * GAO);
            [_zhuche setTitle:@"注册" forState:(UIControlStateNormal)];
        [_zhuche.layer setBorderWidth:1.0];
        
            [_zhuche addTarget:self action:@selector(zhuche:) forControlEvents:(UIControlEventTouchUpInside)];
        [_zhuche setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        
        
        [_login addSubview:_zhuche];
        
        
        /**<  删除table */
       
        [self.view addSubview:_login];
    }else{
        /**<  创建table */
        
        
        [_login removeFromSuperview];
      
    }
    
    
    
    
    
    
    
    
    [self.navigationController.navigationBar setBackgroundImage:  btn.selected ? [UIImage imageWithColor:[UIColor clearColor]] : [UIImage imageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:[UIColor clearColor]]];
    
    [UIView animateWithDuration:kICSDrawerControllerAnimationDuration
                          delay:0
         usingSpringWithDamping:kICSDrawerControllerClosingAnimationSpringDamping
          initialSpringVelocity:kICSDrawerControllerOpeningAnimationSpringInitialVelocity
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         
                         _menuVC.view.transform = btn.selected ?CGAffineTransformIdentity : CGAffineTransformMakeRotation(-M_PI_2);
                         btn.transform = btn.selected ? CGAffineTransformMakeRotation(M_PI_2) : CGAffineTransformIdentity;
                     }
                     completion:^(BOOL finished) {
                     }];
}
-(void)dengru:(UIButton*)button
{
    NSLog(@"登入成功");
}
-(void)zhuche:(UIButton*)button
{
    NSLog(@"注册成功");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
